#ifndef _AYOO_EXCEPTION_H_
#define _AYOO_EXCEPTION_H_
#include <string>
#include "stdarg.h"
#include <exception>

namespace AYOO{

class AyooException : public std::exception
{

public:
	AyooException(int32_t iCode, const std::string& sMessage )
	: m_iCode(iCode), m_sMessage(sMessage) 
	{}

	AyooException(int32_t iCode, const char* szFmt, ... )
	{
	va_list args;
	va_start( args, szFmt );

		char szBuff[2048];
		memset(szBuff, 0x00, sizeof(szBuff));
		vsprintf(szBuff, szFmt, args);
		if(0x00!=szBuff[sizeof(szBuff)-1])
			szBuff[sizeof(szBuff)-1] = 0x00;
		m_sMessage = szBuff;
		m_iCode = iCode;

	va_end( args );
	}

	virtual ~AyooException() throw() 
	{}

	virtual int which()
	{
		return this->m_iCode;
	}

	virtual const char* what() const throw() 
	{
		if (m_sMessage.empty()) 
			return "Default AyooException.";
		else
			return m_sMessage.c_str();
	}


protected:
	int32_t m_iCode;
	std::string m_sMessage;

};

}; /*namespace:AYOO*/

#endif /*_AYOO_EXCEPTION_H_*/

